From the Firehose

Checked checkbox jquery

jQuery also has a checked property that can be used to check if a checkbox is checked or not. Use propery 0th index of the jQuery object. Example: $('#light')[0].checked

// select the element
  let light = $('#light');
  let output = $('#output');

  // add onchange event to checkbox
  light.onchange = function() {
    if (light[0].checked) {
      output.html('The light is on');
    } else {
      output.html('The light is off');
    }
  };

Category: Git | Comments: 0

Comments: 0

About

Customize this section to tell your visitors a little bit about your publication, writers, content, or something else entirely. Totally up to you.